package jxtend.processor.eclipse.visitor.handler;


import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NameReference;
import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.lookup.Scope;

@SuppressWarnings("restriction")
public class AbstractASTNodeVisitorHandler implements ASTNodeVisitorHandler {

	@Override
	public void beginVisit(ASTNodeHandlerVisitorContext context, ASTNode node, Scope scope) {
		// Do nothing
	}

	@Override
	public boolean endVisitBeforeResolve(ASTNodeHandlerVisitorContext context, ASTNode node, Scope scope) {
		return true;
	}

	@Override
	public void endVisitAfterResolve(ASTNodeHandlerVisitorContext context, ASTNode node, Scope scope) {
		// Do nothing
	}

	@Override
	public boolean shouldResolve(ASTNodeHandlerVisitorContext context, ASTNode node, Scope scope) {
		return (node instanceof AbstractVariableDeclaration) || (node instanceof TypeReference)
				|| (node instanceof NameReference)
				|| (node instanceof TypeDeclaration && context.findParentNode(AbstractMethodDeclaration.class) != null
						&& !(context.getParentNode() instanceof QualifiedAllocationExpression));
	}
}
